﻿CREATE PROCEDURE sec_Menu_XML
AS

DECLARE @MENU_LABEL sysname
SET @MENU_LABEL = 'ddMenu_'

SELECT 1 as Tag, NULL as Parent,
	@MENU_LABEL+CAST(M.ParentMenuID as sysname) as [WM:DROPMENU!1!id],
	'nbDropMenu' as [WM:DROPMENU!1!class],
	'true' 			 as [WM:DROPMENU!1!HOLDSTYLE],
	'treeMenu' 			 as [WM:DROPMENU!1!menuName],
	M.ParentMenuID as [WM:DROPMENU!1!pid],
	null as [WM:MENUROW!2!menuID],
	null as [WM:MENUROW!2!WM:MENUITEM!xmltext],
	NULL as [WM:MENUROW!2!x]
FROM v_Menu_Level_0 M --INNER JOIN t_Menu_Group ON M.ParentMenuID = t_Menu_Group.MenuID
INNER JOIN dbo.fs_StateID(DEFAULT,128) fs_Menu ON M.ParentMenuID = fs_Menu.ID
WHERE M.ParentMenuID <> 0

UNION ALL

SELECT 2,1,
	NULL,
	NULL,
	NULL,
	NULL,
	M.ParentMenuID,
	M.MenuID,
	'<T type="default"><WM:MENUITEMIMG><IMG SRC="images/MainMenu/'+Icon+'" WIDTH="16" HEIGHT="16"></WM:MENUITEMIMG>'+
	'<WM:MENUITEMCAPTION captionStyle="font-family:tahoma;font-size:9pt;padding-bottom:4px;'+
		ISNULL(M.Style,CASE M.IsQueue WHEN 1 THEN 'font-weight:bold' ELSE '' END)+
		'">'+M.MenuLable+'</WM:MENUITEMCAPTION>'+
	'<WM:MENUITEMSCRIPT>
		'+@MENU_LABEL+cast(M.ParentMenuID as sysname)+'.hide();
		showSubMenuItem('+
			cast(M.MenuID as sysname)+',"'+
			dbo.Menu_FormatParam(Params,DEFAULT)+'","'+
			dbo.Menu_FormatParam(Action,M.MenuID)+'","'+
			dbo.Menu_FormatParam(Attributes,DEFAULT)+'","'+
			dbo.Menu_FormatParam(Heading,DEFAULT)+'","'+
			MP.MenuName+' -> '+M.MenuLable+'","'+
			dbo.Menu_FormatParam(OnOpen,'')+'","'+
			dbo.Menu_FormatParam(OnRowClick,'')+'")
	</WM:MENUITEMSCRIPT></T>',
	M.TabIndex
FROM v_Menu_Level_N M
INNER JOIN v_Menu_Level_0 MP on M.ParentMenuID = MP.ParentMenuID
INNER JOIN dbo.fs_StateID(DEFAULT,128) fs_Menu ON M.MenuID = fs_Menu.ID
WHERE M.ParentMenuID <> 0
ORDER BY [WM:DROPMENU!1!pid],[WM:MENUROW!2!x]

FOR XML EXPLICIT
--//showMenuItem('+cast(M.MenuID as sysname)+','''+Params+''','''+Action+''','''+Attributes+''','''+Heading+''');






